﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Configuration;
using log4net;
using CubaSite.Utilidades;

public partial class Pages_ContactUs : System.Web.UI.Page
{
    private readonly ILog log = LogManager.GetLogger("LogFile");

    protected override void InitializeCulture()
    {
        if (!IsPostBack)
        {
            string lang = Request.QueryString["lang"];
            if (string.IsNullOrEmpty(lang))
                return;
            CubaSite.Configuracion.LanguageUtilities.ChangeLanguageFromContext(lang);
        }
        else
            CubaSite.Configuracion.LanguageUtilities.SetLanguageFromContext();
        base.InitializeCulture();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        
    }

    protected void EnviarLinkButton_Click(object sender, EventArgs e)
    {
        ErrorAlert.Visible = SuccessAlert.Visible = false;
        string email = "admin@cuba.com.bo";
        try
        {
            email = ConfigurationManager.AppSettings["ContactEmail"];
        }
        catch (Exception ex)
        {
            log.Error("No se pudo obtener el correo de contacto del archivo de configuracion", ex);
            email = "cscristianos@cscristianos.com";
        }

        string FilePath = Server.MapPath("~/MessagesTemplates/ContactMessage.htm");
        string message = "";
        bool enviado = false;
        if (File.Exists(FilePath))
        {
            message = File.ReadAllText(FilePath);
            message = message.Replace("[NAME]", NombreTextBox.Text);
            message = message.Replace("[EMAIL]", EmailTextBox.Text);
            message = message.Replace("[MESSAGE]", MensajeTextBox.Text.Replace("\n", "<br />"));
            enviado = EmailUtilites.SendEmail(EmailTextBox.Text, email, "Consulta", message, true);
        }
        if (!enviado)
        {
            ErrorAlert.Visible = true;
            return;
        }
        SuccessAlert.Visible = true;
    }
}